﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace GraphicsEditor
{
    public class DrawRect : DrawingTool
    {
        public DrawRect()
        {
            pixelDown = new Point(0, 0);
            pixelUp = new Point(0, 0);
        }
        public override void mouseMoved(Point mouseLoc, PictureBoxAdvance pictureWindow, ImageForm imageform, bool mouseDown)
        {
            base.mouseMoved(mouseLoc, pictureWindow, imageform, mouseDown);
            if (drawTime > 3)
            {
                paintSelection(null, pictureWindow, false);
                drawTime = 0;
            }
        }
        public override void paintSelection(Graphics gfx, PictureBoxAdvance pictureWindow, bool zoom)
        {
            if (cleanBitmap == null)
                cleanBitmap = new Bitmap(pictureWindow.Image);
            if (dirty)
            {
                Bitmap refreshImage = new Bitmap(cleanBitmap);
                pictureWindow.Image = refreshImage;
                gfx = Graphics.FromImage(refreshImage);

                SolidBrush brush = new SolidBrush(ToolBox.selectedColor);
                Pen pen = new Pen(brush, ToolBox.PixelSize);

                Rectangle rect = getRectFromPoints(pixelDown, pixelUp);

                gfx.DrawRectangle(pen, rect);
                
                dirty = false;

                pen.Dispose();
                brush.Dispose();
            }
        }
    }
}
